//
//  ByCellWithdraw.m
//  chequanbao_ios
//
//  Created by mc on 2017/6/20.
//  Copyright © 2017年 com.itboye. All rights reserved.
//

#import "ByCellWithdraw.h"

@implementation ByCellWithdraw
{
    UIImageView *_imgView;
    UIButton    *_selectBtn;            // 选中视图

}


+ (instancetype)cellWithTableView:(UITableView*)tableView{
    
    static NSString *cellIdentifier = @"ByCellWithdraw";
    ByCellWithdraw *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        cell.backgroundColor = [UIColor colorWithWhite:1 alpha:0.25];
    }
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSeparatorStyleNone;
        [self setupUI];

    }
    return self;
}

- (void)setupUI {
    
    // 主图
    _imgView = [[UIImageView alloc] init];
    [self.contentView addSubview:_imgView];
    
    
    // 选中视图
    _selectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_selectBtn setImage:[UIImage imageNamed:@"mine_grayyuan"] forState:UIControlStateNormal];
    [_selectBtn setImage:[UIImage imageNamed:@"mine_lanyuan"] forState:UIControlStateSelected];
    [self.contentView addSubview:_selectBtn];
    _selectBtn.userInteractionEnabled = NO;
    
}


-(void)setImgStr:(NSString *)imgStr{
    _imgStr = imgStr;
    [self setNeedsLayout];
}

- (void)setSelect:(BOOL)select {
    
    _select = select;
    _selectBtn.selected = _select;
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    CGFloat x = (SCREEN_WIDTH - 190 - 20 - 40)/2;
    
    // 选择
    _selectBtn.frame = CGRectMake(x, 15 + (190/5 - 20) / 2, 20, 20);
    
    // 图片
    _imgView.frame = CGRectMake(_selectBtn.right + 40, 15, 190, 190 / 5);
    _imgView.image = [UIImage imageNamed:_imgStr];
    
//    // 图片
//    _imgView.frame = CGRectMake(40, 15, 190, 190/5);
//    
//    
//    // 选择
//    _selectBtn.frame = CGRectMake(_imgView.right + 40, 15 + (190/5 - 20)/2, 20, 20);
//
//    
//   
//    _imgView.image = [UIImage imageNamed:_imgStr];
    
}

@end
